// 引入mongoose
const mongoose = require("mongoose");
const { orders } = require("./data/orders.js");
// 创建模型
const orderSchema = new mongoose.Schema({
    userId: {
        type: "ObjectId",
        ref: "users"
    }, //用户 id
    commoditiesId: {
        type: "ObjectId",
        ref: "commodities"
    }, //商品 id
    time: String, //下单时间
    state: String, //订单状态(已完成、进行中)
    price: Number,  //订单价格
    // orderInfo: Array, //订单信息
});

const ordersModel = mongoose.model("orders", orderSchema, "orders");

mongoose.connect(
  "mongodb://tangzhenhua:Lovo123456@182.92.214.223:8084/maiwenjie-project",
  {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    auth: { authSource: "admin" },
  },
  async () => {
    // 当连接成功后触发
    // 创建电影数据 一个（对象）或多个（数组）
    await ordersModel.create(orders);

  }
);
